<template>
  <div class="addCheckwork">
    <h3 class="title">添加考勤</h3>
    <el-form
      :model="ruleForm"
      status-icon
      :rules="rules"
      ref="ruleForm"
      label-width="150px"
      class="demo-ruleForm"
    >
      <el-form-item label="内容" prop="content">
        <el-input type="textarea" autosize v-model="ruleForm.content">
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" :plain="true" @click="submitForm('ruleForm')"
          >发送</el-button
        >
        <el-button type="info" :plain="true" @click="resetForm('ruleForm')"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import userRequest from "../request/user";
export default {
  data() {
    var content = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("请填写消息内容"));
      } else {
        return callback();
      }
    };

    return {
      ruleForm: {
        content: "", //公告内容
      },
      rules: {
        content: [{ validator: content, trigger: "blur" }],
      },
    };
  },

  methods: {
    // 添加考勤
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          userRequest
            .addcheckwork({
              content: this.ruleForm.content,
            })
            .then((res) => {
              if (res.data.success == true) {
                this.$message.success("发布成功!");
                this.resetForm();
              } else {
                this.$message.error(res.data.message);
              }
            });
        } else {
          this.$message.error("请检查信息是否完整！");
          return false;
        }
      });
    },
    // 清空表单
    resetForm() {
      this.$refs.ruleForm.resetFields();
    },
  },

  created() {},
};
</script>

<style lang="scss" scoped>
.addCheckwork {
  overflow: hidden;

  ::v-deep .demo-ruleForm {
    width: 700px;
    margin-top: 50px;
  }
  ::v-deep .el-input__inner {
    height: 45px;
    font-size: 16px;
  }
  ::v-deep .el-form-item__label {
    font-size: 16px;
    position: relative;
    top: 5px;
  }
  ::v-deep .el-form-item__content {
    margin-top: 10px;
    height: 50px;
    display: flex;
  }
  ::v-deep .el-form-item__error {
    font-size: 16px;
  }
}
</style>